import java.util.Arrays;
class Test { 

	public static void main(String[] args) {
	
	
		
	char c1 = 'a';
	int i1 = (int) c1;
	System.out.printf("value of is  %f",(float) i1);
//Area of circle
	double radius;
	double area;
	final double PI=3.14159;
	//radius=20;
	System.out.println(radius=20);
	area=radius*radius*PI;
	System.out.println("The area of radius "+radius+" is "+area); 
	
//Addition of two numbers 
//Addition of three numbers
	int a1;
	int b;
	int c;
	int sum_of_2;
	int sum_of_3;
	a1=5;
	b=6;
	c=7;
	sum_of_2=a1+b;
	sum_of_3=a1+b+c;


	System.out.println("\n\nThe Sum of "+a1+"+"+b+"="+sum_of_2);
	System.out.println("The Sum of "+a1+"+"+b+"+"+c+"="+sum_of_3);

//Pg 26
	double A=1.0;
	System.out.println("\n\n A="+A);
	System.out.println(A+"-0.1= "+(A-=0.1));

	System.out.println(0.9+"-0.1= "+(.9-0.1));

	System.out.println(A+"-0.1= "+(A-=0.1));
	System.out.println(A+"-0.1= "+(A-=0.1));
	System.out.println(A+"-0.1= "+(A-=0.1));
	System.out.println(A+"-0.1= "+(A-=0.1));	
	
	
	
	System.out.println(1.0-0.1-0.1-.1-.1-.1);

//Pg 27
	System.out.println("\n\n 1.0/3.0 is "+ 1.0/3.0);
	System.out.println("1.0f/3.0f is "+ 1.0f/3.0f);

//pg 28
	double fahrenheit = 100;
	double celsius = (5.0 / 9) * (fahrenheit-32);
	System.out.println("\n\nFahrenheit "+ fahrenheit + " is " + celsius +
	 " in Celsius");

//pg 30	
	byte i = 100;
	long k = i * 3 + 4;
	double d = i * 3.1 + k / 2;
	System.out.println("\n\n" + i);
	System.out.println(k);	
	System.out.println(d);

//pg 31
	float f = 10.1f;
	System.out.println(f);

//pg 33
	System.out.println("Hello \"Java\" and \'is Case Sensitive\'\\");
	
//pg 33
	char g = (char)0XAB0041;
	System.out.println(g);

	char e = (char)65.25;
	System.out.println(e);	

	int ii = (int)'A';
	System.out.println(ii);
//pg 34

	String msg = "Welcome" + "to" + "Java";
	
	String s = "Chapter" + 2;

	String s1 = "Supplement" + 'B';
	
	System.out.println(msg);
	System.out.println(s);
	System.out.println(s1);
/**/
	
//parsing int
	
		String str = "1";
		System.out.println("\n\nParsing int");
		System.out.println(int_parsing(str));
	/*//parsing int
	
		String str = "amit";
		System.out.println("\n\nParsing int");
		System.out.println(int_parsing(str));
	
	
	*/
	System.out.println("parsing String \"amit\" Result: \tNumber Format Exception");
	
//parsing double
		
		String str3 = "1.5";
		System.out.println("\n\nParsing double");
		System.out.println(double_parsing(str3));
	
//Cheak Whether leap Year or not
	
	System.out.printf("\n\nCheak Whether leap Year or not\n\tTest 1: Year is 2004 . Result : " + isLeapYear(2004));
	System.out.printf("\n\tTest 2: Year is 2000 . Result : " + isLeapYear(2000));
	System.out.printf("\n\tTest 3: Year is 1996 . Result : " + isLeapYear(1996));
	System.out.printf("\n\tTest 1: Year is 2013 . Result : " + isLeapYear(2013));
	
	
//Find Whether Even or Odd
	
	System.out.printf("\n\nEven Or Odd \n \tTest 1: Number is 2 " + isEven(2));
	System.out.println("\n \tTest 2: Number is 3 " + isEven(3));
	
//To find prime or not
	System.out.println("\n\nTo find prime or not\n \tTest1 : Number is 1 " + isPrime(1));
	System.out.println("\n\tTest2 : Number is 2 " + isPrime(2));
	System.out.println("\n\tTest3 : Number is 4 " + isPrime(4));
	System.out.println("\n\tTest3 : Number is 2147483647 " + isPrime(2147483647));
	/*
//Switch for Double 
	
	float f=5.79f;
	
	switch(f){
	
		case 5.0 : System.out.println("\n Switch SUCCESS \n Result is 5");
					break;
		default	:System.out.println("\n Switch FAILURE ");
	
	}
	*/
	System.out.println("\n\n Switch for Double Result: \t Loss of presicion");
	
//Switch for fall-thru 

	System.out.println("\n\n Switch for Fall-Thru");
	int b1=5;
	
	switch(b1){
	
		case 1 : System.out.println("\n \tValue was 1");
		case 2 : System.out.println("\n \tValue was 2");break;
		case 5 : System.out.println("\n \tResult was 5");
					
		case 6 : System.out.println("\n \tValue was 6");
		default	:System.out.println("\n \tSwitch FAILURE ");
	
	}
	
//Wap to Print in a Loop
	System.out.println("\n\nWap to Print in a Loop 50 times");
	int counter=1;
	while(counter<=50) {
	
		System.out.printf("\n%d   .I will practice Everyday",counter);
		counter++;
	}
	
	
//Wap to print Even nos between 0 to 10
	System.out.println("\n\n Wap to print Even nos between 0 to 10");
	int j = 1;
	while(j<=10){
		if(isEven(j))
			System.out.print(j+",");
		j++;
	}
//Wap to print Odd nos between 10 to 50
	System.out.println("\n\n Wap to print Odd nos between 10 to 50");
	int j1 = 10;
	while(j1<=50){
		if(!(isEven(j1)))
			System.out.print(j1+",");
		j1++;
	}
	
//find max prime number
	System.out.println("\n\nfind max prime number");
	
/*	
	long lPrime;
	long counter1;
	for(counter1 = 2;counter1<=9223372036854775807L ;counter1++)	{	
		
		for(int ip=2; ip <= counter1/2;ip++) {
			if(counter1%ip == 0)
				break;
		}
	}
	lPrime = counter1;
	
	System.out.println("Largest Prime is " + lPrime);*/
	
	long lPrime=97L;
	System.out.println("start : " + lPrime);
	System.out.println("prime test : " + isPrime(lPrime));
	
	
	do{
	System.out.print("hi");
		boolean res1 = isPrime(lPrime);

	if(res1)
			break;
		lPrime--;
		
	}while(true);
	
//Max of two nos.

	System.out.println("\n\nMax of two nos.");
	System.out.println("max(4,5) is " + max(4,5));
	System.out.println("max(-1.3,-0.3) is " + max(-1.3,-0.3));
//Fibbonacci  0 1 1 2 3 5 8 13 21 34 55
	
	System.out.println("\n\n Find fibonacci upto 20 is : "); fibonacci(10);
	//calculate sum of array Elements		
		int[] a2 = {1,1,1,1,1,1,1,1,1,1};
		System.out.println("Sum of Array elements is: " + Calculator.Sum_of_Array(a2));
	
//Random integer Array	
		System.out.println("\n\n Integer Array of 20 nos. ");
		Calculator.print_int(Calculator.rand_int(20));
		System.out.println("\n\nSum of Array elements is: " + Calculator.Sum_of_Array(Calculator.rand_int(10)));
		
//Random integer double		
		System.out.println("\n\n Double Array of 20 nos. ");
		Calculator.print_double(Calculator.rand_double(20));
		
//Random integer Char
		System.out.println("\n\n Char Array of 20 nos. ");
		Calculator.print_char(Calculator.rand_char(20));
		
	
	
	
//max in an array
			int[] arr=Calculator.rand_int(10);
			int max = Calculator.max_arr(arr);
			
			System.out.println("\n\nMax in Array"); 
			Calculator.print_int(arr);
			System.out.println("is : " + max);
// reverse an integer array
			System.out.println("\n\n INT Array");
			Calculator.print_int(arr);
			int[] rev = Calculator.rev_int(arr);
			
			System.out.println("\n\n Reversed  INT array is:"); 
			Calculator.print_int(rev);
			
// reverse an Char array			
			
			char[] arr1 =  Calculator.rand_char(10);
			System.out.println("\n\n Char Array");
			Calculator.print_char(arr1);
			char[] rev1 = Calculator.rev_char(arr1);
			
			System.out.println("\n\n Reversed CHAR array is:"); 
			Calculator.print_char(rev1);
//Count no. of vowels

			char[] arr2 =  Calculator.rand_char(10);
			System.out.println("\n\n Char Array");
			Calculator.print_char(arr2);
			int count = Calculator.count_vowel(arr2);
			System.out.println("\nNo. of Vowels is :" + count);
			
//Generate even nos between num1 & num2
		System.out.println("\n\nGenerate even nos between num1 & num2");
		int[] even = Calculator.gen_even(10,100);
		Calculator.print_int(even);
//Generate Odd nos between num1 & num2
		System.out.println("\n\nGenerate Odd nos between num1 & num2");
		int[] odd = Calculator.gen_odd(10,100);
		Calculator.print_int(odd);
//Generate Prime nos between num1 & num2
		System.out.println("\n\nGenerate Prime nos between num1 & num2");
		int[] prime = Calculator.gen_prime(0,100);
		Calculator.print_int(prime);
//Linear Search
		int[] linear = Calculator.rand_int(20);
		int key = 50;
		System.out.println("\n\nLinear search\n array is : ");
		Calculator.print_int(linear);
		System.out.println("\nKey is :"+key +"  Res is :"+ Calculator.linear_search(linear,key)+"Pos");
//Binary search
		int[] binary = {10,50,60,70,90};
		int bkey = 50;
		System.out.println("\n\nBinary search\n array is : ");
		Calculator.print_int(binary);
		System.out.println("\nKey is :"+bkey +"  Res is :"+ Calculator.binary_search(binary,bkey)+"Pos");

//Fibonacci using array

		int[] fibbo = Calculator.gen_fibbo(10);
		System.out.println("\n\nFibbonacci ");
		Calculator.print_int(fibbo);
		
		
	
//Generate and print 2D Array
		int row = 5;
		int col = 5;
		System.out.println("\n\nGenerate a 2D Random Array and print it");
		int[][] matrix = Calculator.generateRandomMatrix(row,col);
		Calculator.printMatrix(matrix);
	
//Add two matrix A and B with same sizes
		int[][] matA = Calculator.generateRandomMatrix(2,2);
		System.out.println("\n\nAdd two Matrix A & B \n Matrix A:");
		Calculator.printMatrix(matA);
		int[][] matB = Calculator.generateRandomMatrix(2,2);
		System.out.println("\nMatrix B:");
		Calculator.printMatrix(matB);
		int[][] sum = Calculator.addMatrix(matA,matB);
		System.out.println("\n\nMatrix Sum:");
		Calculator.printMatrix(sum);
		
//Multiply two matrix A and B mXn and pXq where p = n 
		int[][] matC = Calculator.generateRandomMatrix(3,2);
		//int[][] matC = {{3,2},{5,6}};
		System.out.println("\n\nMultiply two Matrix A & B \n Matrix A:");
		Calculator.printMatrix(matC);
		int[][] matD = Calculator.generateRandomMatrix(2,3);
		//int[][] matD = {{1,2},{3,1}};
		System.out.println("\nMatrix B:");
		Calculator.printMatrix(matD);
		int[][] mul = Calculator.mulMatrix(matC,matD);
		System.out.println("\n\nMatrix Mul:");
		Calculator.printMatrix(mul);	
// 3x2 Matrix

		int[][] mat1 = {{1,1},{1,1},{1,1}};
		
		System.out.println("\n\nMatrix 3x2:");

		Calculator.printMatrix(mat1);	
		System.out.println("\n\nValue of mat1.length is:" + mat1.length + " Rows");
// 2x3 Matrix

		int[][] mat2 = {{1,1,1},{1,1,1}};
		
		System.out.println("\n\nMatrix 2x3:");
		Calculator.printMatrix(mat2);	
		System.out.println("\n\nValue of mat2[0].length is:" + mat2[0].length + " Cols");

		
//Sum of all Elements 

		System.out.println("\n\nSum of all Elements ");
		Calculator.printMatrix(matC);	
		long sumAll = Calculator.sumMatrix(matC);
		System.out.println("Value is:" +sumAll);
		
//Sum of each row  

		System.out.println("\n\nSum of each row ");
		Calculator.printMatrix(matC);	
		int sumR[] = Calculator.sumRow(matC);
		System.out.println("Result:");
		Calculator.printArray(sumR);
//Sum of each col

		System.out.println("\n\nSum of each col ");
		Calculator.printMatrix(matC);	
		int sumC[] = Calculator.sumCol(matC);
		System.out.println("Result:");
		Calculator.printArray(sumC);
	

// Bubble Sort

		int[] matBS = Calculator.generateRandomArray(10);

		System.out.print("\n\nBubble Sort \t");
		Calculator.printArray(matBS);
		Calculator.bubbleSort(matBS);
		
		System.out.print("\nBubble Sorted   ");
		Calculator.printArray(matBS);
		
// Selection Sort

		int[] matS = Calculator.generateRandomArray(10);
		//int[] matS = {10,2,3,7,5};
		System.out.print("\n\nSelection Sort  \t");
		Calculator.printArray(matS);
		Calculator.selectionSort(matS);
		
		System.out.print("\nSelection Sorted   ");
		Calculator.printArray(matS);		
//Create employee class add 5 record  and print
		Employee E1 = new Employee(12,"amit","bangalore",'M',200000.0);
		Employee E2 = new Employee(13,"guru","bangalore",'M',20000.0);
		Employee E3 = new Employee(14,"sachin","bangalore",'M',20000.0);
		Employee E4 = new Employee(15,"praveen","bangalore",'M',20000.0);
		Employee E5 = new Employee();
		int[] Array = new int[3];
		System.out.println("\nArray value present is \t" + Array);
		System.out.println("\nE1 value present is \t" + E1);
		
		System.out.println("\n\n ID\t NAME \t ADDRESS \t GENDER  SALARY");
		System.out.println("-------------------------------------------------------");
		E1.print();
		E2.print();
		E3.print();
		E4.print();
		E5.print();
// print default values of all primitive data types
		Calculator test = new Calculator();
		test.print();
		
//Arrays.sort 
		int[] a = Calculator.generateRandomArray(20);
		System.out.println("\nUn sorted Array");
		Calculator.printArray(a);
		
		Arrays.sort(a);
		
		System.out.println("\n\nSorted Array");
		Calculator.printArray(a);
//Arrays.binear_search
		
		System.out.println("\n\nBinary Search - Array");
		Calculator.printArray(a);
		
		int res;
		res = Arrays.binarySearch(a,4);
		System.out.println("\nKey is 4");
		System.out.println("Result \t"+(res + 1 ));
		
		/* System.out.println("\nKey is -1");
		res = Arrays.binarySearch(a,-1);
		System.out.println("Result \t"+(res +1 ));
		
		System.out.println("\nKey is 9");
		res = Arrays.binarySearch(a,9);
		System.out.println("Result \t"+(res +1)); */
		
	}

	public static void fibonacci(int num) {
		
		int first=0,second=1,next;
		for(int i=0;i<=num;i++) {
			System.out.print(first +",");
			next = first + second;
			
			first = second;
			second = next;
			
		}
		return ;
	}
	public static int max(int num1,int num2) {
		
		return ((num1<num2)?num2:num1);
	}
	
	public static double max(double num1,double num2) {
		return ((num1<num2)?num2:num1);
	}
	public static boolean isPrime(long num) {
		boolean result = false;
		long count = 0;
		long i=2;
		while(i <= num/2) {
		
			if(num%i == 0)
				count++;
			i++;
		}
		if(count == 0 && num != 1)
			result = true;
		return result;
	}
	public static boolean isPrime(int num) {
		boolean result = false;
		int count = 0;
		int i=2;
		while(i <= num/2) {
		
			if(num%i == 0)
				count++;
			i++;
		}
		if(count == 0 && num != 1)
			result = true;
		return result;
	}
	
	public static boolean isEven(int num) {
		boolean result = false;
		if(num % 2 == 0)
			result = true;
		return result;
		
	}
	public static boolean isLeapYear(int year) {
		
		boolean result = false;
		if(((year%4 == 0)&&(year % 100 != 0))||(year%400 == 0))
			result = true;
		return result;
	
	}
	
	
	
	public static int int_parsing(String str1) {
	
		return Integer.parseInt(str1); 
	}
	
	public static double double_parsing(String str2) {
	
		return Double.parseDouble(str2); 
	}
}